<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>个人备忘录</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    }

    body {
      background-color: #f5f7fa;
      color: #333;
      line-height: 1.6;
      padding: 20px;
    }

    .container {
      max-width: 800px;
      margin: 0 auto;
    }

    header {
      text-align: center;
      padding: 20px;
      background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
      color: white;
      border-radius: 10px;
      box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    }

    h1 {
      font-size: 2.5rem;
      margin-bottom: 10px;
    }

    .subtitle {
      font-size: 1.1rem;
      opacity: 0.9;
    }

    .memo-app {
      background: white;
      border-radius: 10px;
      box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
      overflow: hidden;
    }

    .input-section {
      padding: 25px;
      background-color: #f9f9f9;
      border-bottom: 1px solid #eee;
    }

    .input-group {
      display: flex;
      gap: 10px;
      margin-bottom: 15px;
    }

    input,
    textarea {
      flex: 1;
      padding: 12px 15px;
      border: 1px solid #ddd;
      border-radius: 5px;
      font-size: 16px;
      transition: border 0.3s;
    }

    input:focus,
    textarea:focus {
      border-color: #3498db;
      outline: none;
      box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
    }

    textarea {
      min-height: 100px;
      resize: vertical;
    }

    .btn {
      padding: 12px 20px;
      border: none;
      border-radius: 5px;
      font-size: 16px;
      font-weight: 600;
      cursor: pointer;
      transition: all 0.3s;
    }

    .btn-primary {
      background-color: #3498db;
      color: white;
    }

    .btn-primary:hover {
      background-color: #2980b9;
    }

    .btn-edit {
      background-color: #2ecc71;
      color: white;
    }

    .btn-edit:hover {
      background-color: #27ae60;
    }

    .btn-delete {
      background-color: #e74c3c;
      color: white;
    }

    .btn-delete:hover {
      background-color: #c0392b;
    }

    .btn-cancel {
      background-color: #95a5a6;
      color: white;
    }

    .btn-cancel:hover {
      background-color: #7f8c8d;
    }

    .memo-list {
      padding: 0;
    }

    .memo-item {
      padding: 20px;
      border-bottom: 1px solid #eee;
      display: flex;
      flex-direction: column;
      transition: background-color 0.3s;
    }

    .memo-item:hover {
      background-color: #f9f9f9;
    }

    .memo-header {
      display: flex;
      justify-content: space-between;
      align-items: flex-start;
      margin-bottom: 10px;
    }

    .memo-title {
      font-size: 1.2rem;
      font-weight: 600;
      color: #2c3e50;
    }

    .memo-date {
      font-size: 0.85rem;
      color: #7f8c8d;
    }

    .memo-content {
      color: #555;
      margin-bottom: 15px;
      white-space: pre-wrap;
    }

    .memo-actions {
      display: flex;
      gap: 10px;
      justify-content: flex-end;
    }

    .empty-state {
      padding: 40px 20px;
      text-align: center;
      color: #7f8c8d;
    }

    .empty-state img {
      max-width: 200px;
      margin-bottom: 20px;
      opacity: 0.5;
    }

    .filter-section {
      padding: 15px 25px;
      background-color: #f1f8ff;
      display: flex;
      justify-content: space-between;
      align-items: center;
      border-bottom: 1px solid #ddd;
    }

    .filter-options {
      display: flex;
      gap: 15px;
    }

    .filter-btn {
      padding: 8px 15px;
      background: white;
      border: 1px solid #ddd;
      border-radius: 20px;
      cursor: pointer;
      transition: all 0.3s;
    }

    .filter-btn.active {
      background-color: #3498db;
      color: white;
      border-color: #3498db;
    }

    .stats {
      font-size: 0.9rem;
      color: #7f8c8d;
    }

    .edit-form {
      display: none;
      padding: 15px;
      background-color: #f1f8ff;
      border-radius: 5px;
      margin-top: 10px;
      border-left: 4px solid #3498db;
    }

    .edit-form.active {
      display: block;
    }

    .edit-actions {
      display: flex;
      gap: 10px;
      margin-top: 15px;
      justify-content: flex-end;
    }

    @media (max-width: 600px) {
      .input-group {
        flex-direction: column;
      }

      .memo-header {
        flex-direction: column;
        align-items: flex-start;
      }

      .memo-date {
        margin-top: 5px;
      }

      .filter-section {
        flex-direction: column;
        gap: 15px;
        align-items: flex-start;
      }

      .memo-actions {
        justify-content: flex-start;
      }
    }

    .memo-app {
      position: relative;
    }

    .logout {
      position: absolute;
      display: block;
      padding: 10px 19px;
      top: 204px;
      right: 26px;
      text-decoration: none;
      color: white;
      background-color: #3498db;
      font-weight: 600;
      border-radius: 5px;
    }

    .waiting {
      font-size: 20px;
      margin-bottom: 0px;
    }
  </style>
</head>

<body>
  <div class="container">
    <header>
      <h1>备忘录</h1>
      <p class="subtitle">记录生活中的重要事项</p>
    </header>

    <div class="memo-app">
      <form method="post" action="/add">
        <div class="input-section">
          <div class="input-group">
            <input name="title" type="text" id="memoTitle" placeholder="输入事项标题...">
          </div>
          <div class="input-group">
            <textarea name="detail" id="memoContent" placeholder="输入事项详情..."></textarea>
          </div>
          <button class="btn btn-primary">添加事项</button>
      </form>
      <a href="/logout" class="logout">退出登录</a>
    </div>

    <div class="filter-section">
      <h1 class="waiting">待办事项</h1>
      <div class="stats">共 <%=n%> 个事项</div>
    </div>

    <div class="memo-list">
      <!-- 示例事项 1 -->
       <% arr.forEach(item=>{ %>
      <div class="memo-item">
        <div class="memo-header">
          <div class="memo-title"><%= item.title%></div>
          <div class="memo-date"><%= item.time%></div>
        </div>
        <div class="memo-content"><%= item.detail%></div>
        <div class="memo-actions">
          <form method="get" action="/change/<%=item._id%>"><button class="btn btn-edit">编辑</button></form>
          <form method="get" action="/delete/<%=item._id%>"><button class="btn btn-delete">删除</button></form>
        </div>
      </div>
       <%})%>
    </div>
  </div>
  </div>
  <script>
    const btns = document.querySelectorAll('.btn-delete')
    btns.forEach(item => {
      item.addEventListener('click', (e) => {
        if (!confirm('确认要删除该事项吗？')) {
          //阻止表单的默认行为(发送http请求)
          e.preventDefault()
        }
      })
    })
  </script>
</body>

</html>